package com.ls.hnks.advice;

import com.ls.hnks.util.Result;
import com.ls.hnks.util.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
@Slf4j
@Order(10086)
public class SQLExceptionHandler {
    /**
     * sql层异常处理
     */
    @ExceptionHandler({SQLIntegrityConstraintViolationException.class})
    public Result excpHandler(SQLIntegrityConstraintViolationException exception) {//捕获到的异常被传到方法的形参里
        log.info("sql异常信息：" + exception.getMessage());
        return Result.error(ResultCodeEnum.ERROR);
    }
}
